unit DBFilter;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, EngDbMain, Vcl.StdCtrls, Vcl.DBCtrls,
  Data.DB;

type
  TfrmFilter = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    cbOwner: TComboBox;
    cbStatus: TComboBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cbOwnerChange(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmFilter: TfrmFilter;

implementation

{$R *.dfm}



procedure TfrmFilter.cbOwnerChange(Sender: TObject);
begin
  frmEngDB.tblPrj.Filter := 'OWNER LIKE ' + QuotedStr(cbOwner.Text +'%') +
                            'AND STATUS = ' + QuotedStr(cbStatus.Text);

end;

procedure TfrmFilter.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  frmEngDB.tblPrj.Filtered := False;
  Action := caFree;      //frees the form from memory
  frmFilter := nil;    //must set object variable to nil
end;

procedure TfrmFilter.FormCreate(Sender: TObject);
begin
  //
end;

procedure TfrmFilter.FormShow(Sender: TObject);
begin
  Top := frmEngDB.Top;
  Left := frmEngDB.Left;
  cbOwner.Items.Add('%');
  frmEngDB.tblResource.First;
  while not frmEngDB.tblResource.Eof do
    begin
      cbOwner.Items.Add(frmEngDB.tblResource.FieldByName('FULL_NAME').AsString);
      frmEngDB.tblResource.Next;
     end;
   frmEngDB.tblPrj.Filtered := True;
end;

end.
